package org.kitrum.example.spring.scan;

import org.kitrum.example.common.annotations.MyAnnotation;
import org.kitrum.example.service.interfaces.RoleService;
import org.kitrum.example.service.interfaces.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;

/**
 * @program: kitrum-example
 * @description:
 * @author: Kun
 * @create: 2021-01-25 14:58
 */
public class ScanApplication {

    public static void run()
    {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(context);

        classPathBeanDefinitionScanner.addIncludeFilter(new AnnotationTypeFilter(MyAnnotation.class));
        int count = classPathBeanDefinitionScanner.scan("org.kitrum.example.service");
        context.refresh();
        UserService userService = context.getBean(UserService.class);
        RoleService roleService = context.getBean(RoleService.class);
        userService.print();
        userService.rolePrint();
        roleService.print();
        roleService.userPrint();
        System.out.println(count);
    }

    public static void main(String[] args) {
        run();
    }
}
